package initialize

import (
	"fmt"
	clientv3 "go.etcd.io/etcd/client/v3"
	"server/global"
	"time"
)

func InitEtcd() {
	dsn := global.XidwConfig.Etcd.Dsn
	global.Logger.Info(fmt.Sprintf("==========================connect to etcd dsn:%s", dsn))
	config := clientv3.Config{
		Endpoints:   []string{dsn},
		DialTimeout: 15 * time.Second,
	}
	cli, err := clientv3.New(config)
	if err != nil {
		global.Logger.Info(fmt.Sprintf("==========================connect to etcd 失败:%s", err))
		global.Etcd = nil
	}
	global.Logger.Info(fmt.Sprintf("==========================connect to etcd 成功:%s", err))
	global.Etcd = cli
}
